Public Class DanoQuest
    Inherits Microsoft.Xna.Framework.Game

    Public UseDebug As Boolean = True

    Public Resolution As New Vector2(1280, 724)
    Public WithEvents Graphics As GraphicsDeviceManager
    Public WithEvents SpriteBatch As SpriteBatch
    Public WithEvents GameManager As New GameManagerCollection
    Public OriginalMouseState As MouseState
    Public ServerProcess As ServerProcess
    Public NetClient As NetworkingClient
    Public KeyboardUtilities As KeyboardUtils

    Public Sub New()
        Graphics = New GraphicsDeviceManager(Me)
        Graphics.PreferredBackBufferWidth = CInt(Resolution.X)
        Graphics.PreferredBackBufferHeight = CInt(Resolution.Y)
        Content.RootDirectory = "Content"
        Me.IsMouseVisible = True
    End Sub

    Protected Overrides Sub Initialize() 'Enumerate through any components and initializes them. Querys for required services and loads non-graphic related content
        ServerProcess = New ServerProcess("C:\Users\LELE\Documents\Visual Studio 2010\Projects\DanoQuest\DanoQuestServer\bin\Debug\DanoQuestServer.exe") With {.Enabled = False}
        KeyboardUtilities = New KeyboardUtils
        MyBase.Initialize()
    End Sub

    Protected Overrides Sub LoadContent()
        SpriteBatch = New SpriteBatch(GraphicsDevice) ' Create a new SpriteBatch, which can be used to draw textures.
        GameManager.TextureManager = New TextureManager(Me)
        GameManager.Camera = New Camera(Me) 'Load camera first, our 3D elements uses the camera
        GameManager.ThreeDElements = New ThreeDElements(Me) With {.TrianglePicking = UseDebug} 'Debugging: TrianglePicking = True
        GameManager.SpriteManager = New SpriteManager(Me) 'Load before player
        GameManager.CollisionManager = New Collision(Me) 'Load before Player
        GameManager.Player = New Player(Me, "Dano", 10, 20)
        GameManager.WorldManager = New WorldManager(Me)
        GameManager.SpawnManager = New SpawnManager(Me)
        GameManager.UserInterface = New UserInterface(Me) With {.DebugOn = UseDebug} 'Manages UI elements ***Moved because TargetUI elements were not initialized yet***
        Mouse.SetPosition(CInt(Resolution.X / 2), CInt(Resolution.Y / 2)) 'Centering Mouse on the screen
        OriginalMouseState = Mouse.GetState
        NetClient = New NetworkingClient
    End Sub

    Protected Overrides Sub UnloadContent()
        ' TODO: Unload any non ContentManager content here
    End Sub

    Protected Overrides Sub Update(ByVal gameTime As GameTime) ' Collisions, gathering input, playing audio, updating the world
        GameManager.UserInterface.UITimeRuler.StartFrame()
        GameManager.UserInterface.UITimeRuler.BeginMark("Update", Color.Blue)
        Dim Amount As Single = CSng(gameTime.ElapsedGameTime.TotalMilliseconds) / 1000.0F
        KeyboardInput(Amount)
        MouseInput(Amount)
        prevKeyState = Keyboard.GetState
        GameManager.UserInterface.Update()
        MyBase.Update(gameTime)
        GameManager.UserInterface.UITimeRuler.EndMark("Update")
    End Sub

    Protected Overrides Sub Draw(ByVal gameTime As GameTime)
        GraphicsDevice.Clear(Color.Green)
        Dim SpriteBatch As New SpriteBatch(GraphicsDevice)
        SpriteBatch.Begin()
        GameManager.ThreeDElements.Draw()
        GameManager.UserInterface.Draw(SpriteBatch)
        SpriteBatch.End()
        MyBase.Draw(gameTime)
    End Sub

End Class